package com.kele.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kele.entity.User;
import com.kele.service.impl.UserServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author kele
 * @since 2022-01-07
 */
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    UserServiceImpl userService;

    @RequestMapping("/getAll")
    public String getAll() {
        log.info("user: {}",userService.getAll());
        List<User> userList = userService.getAll();
        return JSON.toJSONString(userList);
    }

    @RequestMapping("/page")
    public String getByPage (@RequestParam int pageNum, @RequestParam int pageSize) {
        Page<User> page =new Page<>(pageNum,pageSize);
        return JSON.toJSONString(userService.selectPage(page));

    }
}

